define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'bootstrap-table-jumpto'], function ($, undefined, Backend, Table, Form, Jump) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'video/item/index' + location.search,
                    add_url: 'video/item/add',
                    edit_url: 'video/item/edit',
                    del_url: 'video/item/del',
                    multi_url: 'video/item/multi',
                    table: 'video_item',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showExport: false,
                showJumpto: true,
                searchFormVisible: true,
                columns: [
                    [{
                            checkbox: true
                        },
                        {
                            field: 'id',
                            title: __('Id')
                        },
                        {
                            field: 'name',
                            title: __('Name'),
                            operate: 'like'
                        },
                        {
                            field: 'videoitem.name',
                            title: '视频分类',
                            operate: 'like'
                        },
                        {
                            field: 'video_href',
                            title: __('Video_href'),
                            operate: false,
                            formatter: function(v,r){
                                return "<video src='"+v+"' style='width: 180px;height:100px;' controls='controls'>请使用Chrome浏览器，或者360浏览器极速模式</video>";
                            }
                        },
                        {
                            field: 'videocount',
                            title: __('Videocount'),
                            operate: 'RANGE'
                        },
                        {
                            field: 'createtime',
                            title: __('Createtime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});